<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <title>首页</title>
    <include file="public@head" />
    <link rel="stylesheet" href="__TMPL__public/assets/css/star.css"/>
    <style>

    </style>
</head>
<body>
<include file="public@starnav" />

<div class="center-s">
    <div class="home_top text-center">
        <img class="star_avatar" src="" alt=""/>
        <p class="tips">Hi, <span class="star_name">刘涛</span>,大家都在期待着你的直播呢</p>
        <div class="live_set_tool">
            <!--<span id="test" class="btn-set">开播</span>-->
            <span class="btn-set live_time_set">设定</span>
        </div>
    </div>
    <div class="home_schedule">
        <h2 class="title"><span>直播议程</span></h2>
        <div class="time_line_wrap">
            <!--<div class="clearfix time_item">
                <h2 class="fl time_line">今天</h2>
                <ul class="fl time_minute_wrap">
                    <h3 class="time_day">03-15</h3>
                    <li class="time_minute">
                        <span class="minute">11:30</span>
                        <span class="tips_package">预定有红包</span>
                        <span class="tips_gift">预定有礼品</span>
                    </li>
                    <li class="time_minute">
                        <span class="minute">11:30</span>
                    </li>
                </ul>
            </div>
            <div class="clearfix time_item">
                <h2 class="fl time_line">明天</h2>
                <ul class="fl time_minute_wrap">
                    <h3 class="time_day">03-15</h3>
                    <li class="time_minute">
                        <span class="minute">11:30</span>
                    </li>
                    <li class="time_minute">
                        <span class="minute">11:30</span>
                    </li>
                </ul>
            </div>-->
        </div>
    </div>





</div>
<include file="public@footer" />

<include file="public@starscripts" />
<script>
    iService.headerMove(0);

    $(function(){

        $(".star_avatar").attr("src",localStorage.u_avatar);

        var home_param = {
            url:'Stars/starHome',
            data:{
                page:1
            }
        };
        var play_url = [];
        //直播议程
        $.JsonRpc(home_param,function(data){
            if(data.code==200){
                data = data.data.list;
                if(!data.length){
                    var tplNull = "<p class='null-tips-wrap'>当前没有预播信息</p>";
                    $(".time_line_wrap").before(tplNull);
                    return false;
                }
                var live_list = [];
                var index = 0;
                live_list[index] = [];
                for(var k= 0,le=data.length;k<le;k++){
                    live_list[index].push(data[k]);
                    if(k==le-1){
                        break ;
                    }
                    if(data[k].l_date!=data[k+1].l_date){
                        index += 1;
                        live_list[index] = [];
                    }
                }
                var tpl = "";
                $.each(live_list,function(i){
                    var time_line_html="最近",time_day_html;
                    time_day_html = live_list[i][0].l_date.slice(5,10);
                    var day_now = iService.getNowFormatDate("-");
                    if(day_now==live_list[i][0].l_date){
                        time_line_html = "今天";
                    }else if(AddDaysUtil(day_now,1,"-")==live_list[i][0].l_date){
                        time_line_html = "明天";
                    }
                    tpl +=
                        '<div class="clearfix time_item">'+
                        '<h2 class="fl time_line">'+time_line_html+'</h2>'+
                        '<ul class="fl time_minute_wrap">'+
                            '<h3 class="time_day">'+time_day_html+'</h3>';
                    $.each(live_list[i],function(n){
                        var minute_html,tips_package_html,tips_gift_html;
                        minute_html = live_list[i][n].l_startime.slice(0,5);
                        (live_list[i][n].l_package==0)?tips_package_html="":tips_package_html='<span class="tips_package">预定有红包</span>';
                        (live_list[i][n].l_gift==0)?tips_gift_html="":tips_gift_html='<span class="tips_gift">预定有礼品</span>';
                        tpl+=
                            '<li class="time_minute">'+
                            '<span class="minute">'+minute_html+'</span>'+ tips_package_html+tips_gift_html+
                            '</li>';
                    });
                    tpl +=
                        '</ul>'+
                        '</div>';
                });
            }

            $(".time_line_wrap").html(tpl);

        });


        /*layui.use('laydate', function(){
         var laydate = layui.laydate;

         var start = {
         min: laydate.now()
         ,max: '2099-06-16 23:59:59'
         ,istime:true
         ,format: 'YYYY-MM-DD hh:mm:ss'
         ,istoday: false
         ,choose: function(datas){
         }
         };
         document.getElementById('advance_time').onclick = function(){
         start.elem = this;
         laydate(start);
         }
         });*/

        var $live_set_btn = $(".live_time_set");
        $live_set_btn.on("click",function(){

            layui.use(['layer','laydate','form'], function(){
                var form_html =
                        '<div class="layui-form" id="live_content_wrap">'+
                        '<div class="title">设定<span class="close_btn fr"></span></div>'+

                        '</div>';

                var layer = layui.layer;
                layer.ready(function(){
                    var index = layer.open({
                        type: 1,
                        title: false,
                        closeBtn: 0,
                        shadeClose: false, //开启遮罩关闭
                        area: ['520px', '440px'],
                        skin: 'layui-layer-molv',
                        content: form_html,
                        resize:false,
                        offset:'150px',
                        success:function(){
                            var set_init_param = {
                                url:'Stars/advanceEnter',
                                data:{
                                }
                            };
                            $.JsonRpc(set_init_param,setLiveInfo);
                            function setLiveInfo(data){
                                console.log(data);
                                data=data.data;
                                var select_html = null;
                                if(!data.edit){
                                    //不可以编辑
                                    select_html =
                                            '<select disabled="disabled" class="layui-input-inline" name="live_price" lay-verify="">'+
                                            '<option data-value = "'+data.s_price+'" value="'+data.s_price+'">'+data.s_price+'L币</option>'+
                                            '</select>';
                                    $(".live-price-wrap").html();
                                }else {
                                    select_html =
                                            '<select class="layui-input-inline" name="live_price" lay-verify="">'+
                                            '<option value="">请选择价格</option>'+
                                            '<option data-value="5.00" value="5">5L币</option>'+
                                            '<option data-value="5.00" value="5">5L币</option>'+
                                            '<option data-value="5.00" value="5">5L币</option>'+
                                            '</select>';
                                }
                                var tpl =
                                        '<form class="layui-form">'+
                                        '<div class="set-wrap">'+
                                        '<div class="item" style="height: auto;">'+
                                        '<span>当前封面</span>'+
                                        '<div class="layui-inline">'+
                                        '<div class="pic-cover-wrap">' +
                                        '<img class="pic-cover" data-path="" data-file="" src="'+data.s_image+'" /><span class="displayNone" style="display:none;">修改封面</span>' +
                                        '</div>'+
                                        '</div>'+
                                        '</div>'+
                                        '<div class="item">'+
                                        '<span>送福利</span>'+
                                        '<div class="layui-inline">'+
                                        '<input type="checkbox" name="red_package_c" title="发红包" lay-skin="primary">'+
                                        '<input type="checkbox" name="gift_c" title="送礼品" lay-skin="primary">'+
                                        '</div>'+
                                        '</div>'+
                                        '<div class="item">'+
                                        '<span>开播时间</span>'+
                                        '<div class="layui-inline">'+
                                        '<input class="layui-input" id="advance_time" placeholder="请选择预播时间">'+
                                        '</div>'+
                                        '</div>'+
                                        '<div class="item">'+
                                        '<span>价格</span>'+
                                        '<div class="layui-inline live-price-wrap">'+
                                        select_html+
                                        '</div>'+
                                        '</div>'+
                                        '<p class="price-deadline">价格设定一个月后才能更改</p>'+
                                        '<div class="confirm_tool clearfix">'+
                                        '<span class="btn100 btn-s submit">发布</span>'+
                                        '<span class="btn100 btn-c cancel">取消</span>'+
                                        '</div>'+
                                        '</div>'+
                                        '</form>'+
                                        '<div id="cover-modify-wra" class="text-center displayNone">'+
                                            '<img class="cover-img" src="'+data.s_image+'" alt=""><br />'+
                                            '<span>当前封面</span><br />'+
                                            '<form id="back_upload_form" class="upload-form-com clearfix"  enctype="multipart/form-data">'+
                                                '<input class="fl up-txt" id="cover-txt" type="text" disabled>'+
                                                '<span class="uploadBtn small fl"><input id="iuy" onchange="" type="file" accept="image/jpg,image/jpeg,image/png" name=img><span>浏览</span></span>'+
                                                '<div style="clear: both;"></div>'+
                                                '<span class="submit fr">上传</span>'+
                                                '<input name=udid type="hidden" value="">'+
                                                '<input name=token type="hidden" value="">'+
                                            '</form>'+
                                            '<div id="cover-upload-confirm" style="display:none;">'+
                                                '<div style="width: 216px;height: 180px; position: relative; overflow: hidden; display: inline-block; margin: 24px auto 30px;">'+
                                                    '<img style="width:100%" class="cover-new" src="" alt="">'+
                                               '</div>'+
                                               '<div class="clearfix">'+
                                                    '<span class="hc_confirm_btn fr" style="margin-right: 84px;">完成</span>'+
                                                    '<span class="hc_back_btn fr">重新上传</span>'+
                                                '</div>'+
                                            '</div>'+
                                        '</div>';
                                $(tpl).appendTo("#live_content_wrap");
                                $("#iuy").on("change",function(){
                                    $('#cover-txt').val($(this).val());
                                });

                                $("#back_upload_form .submit").on("click",function(){
                                    var file_info = $("#cover-txt").val();

                                    $("input[name=udid]").val(localStorage.udid);
                                    $("input[name=token]").val(localStorage.token);

                                    if(file_info!=""){
                                        var file_form = new FormData($('#back_upload_form')[0]);//提交表单所有数据
                                        $.ajax({
                                            type: "post",
                                            url: "{$spost}Abouts/upload",
                                            data: file_form,
                                            processData:false,
                                            contentType:false,
                                            async: true,
                                            datatype: "JSON",
                                            beforeSend: function(){
                                                var uploading = true;
                                                console.log(uploading);
                                            },
                                            success: function (obj) {
                                                var data = $.parseJSON(obj);
                                                if (data.code == 200) {
                                                    $("#cover-upload-confirm").show();
                                                    $("#back_upload_form").hide();
                                                    var $image = $('#cover-upload-confirm .cover-new');
                                                    var img_url = "{$simgs}"+data.data.path+data.data.file;
                                                    $image.attr("src",img_url);
                                                    $(".pic-cover").attr("src",img_url).data({"path":data.data.path,"file":data.data.file});

                                                    $("#cover-upload-confirm .hc_confirm_btn").attr({"data-file":data.data.file,"data-path":data.data.path})
                                                }
                                                if (data.code == 300) {
                                                    //清除浏览器缓存数据 跳转登录页面，
                                                    alert(data.data.message);
                                                    return false;
                                                }
                                            },
                                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                                console.log(XMLHttpRequest.readyState);
                                                console.log(textStatus);
                                                console.log(errorThrown);
                                            }
                                        });
                                    }

                                    $("#cover-upload-confirm .hc_back_btn").on("click",function(){
                                        $("#cover-upload-confirm").hide();
                                        $("#back_upload_form").show();
                                    });

                                    $("#cover-upload-confirm .hc_confirm_btn").on("click",function(){
                                        $(".set-wrap").show();
                                        $("#cover-modify-wra").hide();
                                    });
                                });

                                var form = layui.form();
                                form.render(); //更新全部
                                form.render('select'); //刷新select选择框渲染

                                var laydate = layui.laydate;
                                var start = {
                                    min: laydate.now()
                                    ,max: '2099-06-16 23:59:59'
                                    ,istime:true
                                    ,format: 'YYYY-MM-DD hh:mm:ss'
                                    ,istoday: false
                                    ,choose: function(datas){
                                    }
                                };
                                document.getElementById('advance_time').onclick = function(){
                                    start.elem = this;
                                    laydate(start);
                                };

                                var pic_cover_wrap = $(".pic-cover-wrap");
                                pic_cover_wrap.hover(function(){
                                    $(this).children("span").show();
                                },function(){
                                    $(this).children("span").hide();
                                });

                                var cover_modify_wra = $("#cover-modify-wra"),
                                set_wrap = $(".set-wrap");
                                pic_cover_wrap.on("click",function(){
                                    cover_modify_wra.show();
                                    set_wrap.hide();
                                });

                                $(".confirm_tool .cancel").on("click",function(){
                                    layer.close(index);
                                });

                                $(".confirm_tool .submit").on("click",function(){

                                    var date_arr = document.getElementById("advance_time").value.split(" ");
                                    var red_package_c,gift_c;
                                    $("input[name=red_package_c]").is(":checked")?red_package_c=10:red_package_c=0;
                                    $("input[name=gift_c]").is(":checked")?gift_c=10:gift_c=0;
                                    var focus_param = {
                                        url:'Stars/advance',
                                        data:{
                                            date:date_arr[0],
                                            star:date_arr[1].slice(0,5),
                                            end:0,
                                            package:red_package_c,
                                            gift:gift_c,
                                            price:$("select[name=live_price] :selected").data("value"),
                                            path:$(".pic-cover").data("path"),
                                            file:$(".pic-cover").data("file")
                                        }
                                    };
                                    $.JsonRpc(focus_param,function(data){
                                        alert(data.data.message);
                                        location.reload();
                                    });
                                });
                            }
                        }
                    });
                    //  layer.close(index);
                    //  console.log(index);
                    $(".title .close_btn").on("click",function(){
                        layer.close(index);
                    });


                });
            });
        });
    });
</script>
</body>
</html>